package com.domino.shared;

import java.io.Serializable;

public class Player implements Serializable {
	
	private PlayerId id;
	private String nickname;
	private String accessToken;
		
	public Player(PlayerId id, String nickname, String accessToken) {
		super();
		this.id = id;
		this.nickname = nickname;
		this.accessToken = accessToken;
	}

	public Player() {
		super();
	}

	private Player(PlayerId playerId, String nickname) {
		this(playerId, nickname, null);
	}

	public PlayerId getId() {
		return id;
	}
	

	public String getNickname() {
		return nickname;
	}

	public String getAccessToken() {
		return accessToken;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Player other = (Player) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Player [id=" + id + ", nickname=" + nickname + "]";
	}

	public boolean isAnonymous() {
		return id.getId().startsWith("A");
	}

	public static Player createAnonymous() {
		int id = (int)System.currentTimeMillis();
		return new Player(new PlayerId("A"+Integer.toString(id)), "Anonymous"+id);
	}

	

}
